﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using RedDragon.ERP.API.Application.Commands.Department;
using RedDragon.ERP.API.Application.Commands.Enterprise;
using System.Globalization;
using T.Common.Domain.Common;

namespace RedDragon.ERP.API.Controllers
{
    /// <summary>
    /// 企业控制器
    /// </summary>
    [Route("api/[controller]")]
    [ApiController]
    public class EnterprisesController : ControllerBase
    {
        private readonly IMediator _mediator;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="mediator"></param>
        public EnterprisesController(IMediator mediator)
        {
            _mediator = mediator;
        }

        /// <summary>
        /// 添加企业信息
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost("CreateEnterprise")]
        public async Task<Result> CreateEnterprise(CreateEnterpriseCommand cmd)
        {
            return await _mediator.Send(cmd);
        }

        /// <summary>
        /// 获取所有企业信息
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpGet("SearchEnterprise")]
        public async Task<Result> SearchEnterprise([FromQuery] SearchEnterpriseCommand cmd)
        {
            return await _mediator.Send(cmd);
        }

        /// <summary>
        /// 树形企业信息
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpGet("SearchTreeEnterprise")]
        public async Task<Result> SearchTreeEnterprise([FromQuery] SearchTreeEnterpriseCommand cmd)
        {
            return await _mediator.Send(cmd);
        }

        /// <summary>
        /// 添加部门信息
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost("CreateDepartment")]
        public async Task<Result> CreateDepartment(CreateDepartmentCommand cmd)
        {
            return await _mediator.Send(cmd);
        }


        /// <summary>
        /// 根据主键ID获取部门上级
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpGet("SearchDepartment")]
        public async Task<Result> SearchDepartment([FromQuery] SearchDepartmentCommand cmd)
        {
            return await _mediator.Send(cmd);
        }

        /// <summary>
        /// 部门树形显示
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpGet("SearchTreeDepartment")]
        public async Task<Result> SearchTreeDepartment([FromQuery] SearchTreeDepartmentCommand cmd)
        {
            return await _mediator.Send(cmd);
        }

        /// <summary>
        /// 无条件获取全部部门
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpGet("SearchAllDepartment")]
        public async Task<Result> SearchAllDepartment([FromQuery] SearchAllDepartmentCommand cmd)
        {
            return await _mediator.Send(cmd);
        }
    }
}
